﻿<!--#include file="zfpay_md5.asp"-->
<%
'正试提交
Function ResultCard(MerId,keyValue,Orderid,Amt,cardNo,cardPwd,FrpId,BackUrls)
	dim hmac
	dim sFormString
	dim returnMsg
        Dim reqURL

	hmac = zfpay_md5(MerId & Orderid & Amt & cardNo & cardPwd & FrpId)
	
	'WAP支付吧请求地址.
	reqURL = "http://zfpay.cn/pay/pay.aspx"
	
        sFormString = ""
	sFormString = sFormString + "MerId=" & MerId
	sFormString = sFormString + "&keyValue=" & keyValue
	sFormString = sFormString + "&Orderid=" & Orderid
	sFormString = sFormString + "&Amt=" & Amt
	sFormString = sFormString + "&cardNo=" & cardNo
	sFormString = sFormString + "&cardPwd=" & cardPwd
	sFormString = sFormString + "&FrpId=" & FrpId
	sFormString = sFormString + "&BackUrls=" & BackUrls
	sFormString = sFormString + "&hmac=" & hmac


	set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
 
	objHttp.open "POST", reqURL, false
	objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
	objHttp.Send sFormString
   
	If (objHttp.status <> 200 ) Then
		'HTTP 错误处理
		returnMsg =objHttp.status
	Else
		
		Dim strCallBack

		strCallBack = trim(objHttp.responseText)
		select case strCallBack
		case "1"
			returnMsg = returnMsg + "提交成功!<br/>"
		case "7"
			returnMsg = returnMsg + "卡密无效!<br/>"
		case "61"
			returnMsg = returnMsg + "账户未开通!<br/>"
		case "112"
			returnMsg = returnMsg + "商户状态不可用,未开通此项卡支持或FrpId传递有误!<br/>"
		case "-1"
			returnMsg = returnMsg + "交易信息被篡改!<br/>"
		case else
			returnMsg = strCallBack
		end select

	End If

	ResultCard = returnMsg

End Function

'接口测试
Function ResultCardTest(MerId,keyValue,Orderid,Amt,cardNo,cardPwd,FrpId,BackUrls)
	dim hmac
	dim sFormString
	dim returnMsg
        Dim reqURL

	hmac = zfpay_md5(MerId & Orderid & Amt & cardNo & cardPwd & FrpId)
	
	'WAP支付吧请求地址.
	reqURL = "http://zfpay.cn/pay/orderdirect.aspx"
	
        sFormString = ""
	sFormString = sFormString + "MerId=" & MerId
	sFormString = sFormString + "&keyValue=" & keyValue
	sFormString = sFormString + "&Orderid=" & Orderid
	sFormString = sFormString + "&Amt=" & Amt
	sFormString = sFormString + "&cardNo=" & cardNo
	sFormString = sFormString + "&cardPwd=" & cardPwd
	sFormString = sFormString + "&FrpId=" & FrpId
	sFormString = sFormString + "&BackUrls=" & BackUrls
	sFormString = sFormString + "&hmac=" & hmac


	set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
 
	objHttp.open "POST", reqURL, false
	objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
	objHttp.Send sFormString
   
	If (objHttp.status <> 200 ) Then
		'HTTP 错误处理
		returnMsg =objHttp.status
	Else
		
		Dim strCallBack

		strCallBack = trim(objHttp.responseText)
		select case strCallBack
		case "1"
			returnMsg = returnMsg + "提交成功!<br/>"
		case "7"
			returnMsg = returnMsg + "卡密无效!<br/>"
		case "61"
			returnMsg = returnMsg + "账户未开通!<br/>"
		case "112"
			returnMsg = returnMsg + "商户状态不可用,未开通此项卡支持或FrpId传递有误!<br/>"
		case "-1"
			returnMsg = returnMsg + "交易信息被篡改!<br/>"
		case else
			returnMsg = strCallBack
		end select

	End If

	ResultCard = returnMsg

End Function

Function CheckHmac(rs_Code,MerId,TrxId,Orderid,Amt,cardNo,FrpId,hmac)

	'取得签名数据前的字符串，一定按照文档中标明的签名顺序进行
        Dim sNewString

	sNewString = zfpay_md5(rs_Code & MerId & TrxId & Orderid & Amt & cardNo &  FrpId)

	If(hmac=sNewString) Then
		CheckHmac = True
	Else
		CheckHmac = False
	End If

End Function
'	取得支付返回数据中的参数
Function getCallBackValue(rs_Code,MerId,TrxId,Orderid,Amt,cardNo,FrpId,hmac)

	rs_Code		=	Request("rs_Code")
	MerId		=	Request("MerId")
	TrxId		=	Request("TrxId")
	Orderid		=	Request("Orderid")
	Amt		=	Request("Amt")
	cardNo		=	Request("cardNo")
	FrpId		=	Request("FrpId")
	hmac		=	Request("hmac")
End Function

%>